home *** CD-ROM | disk | FTP | other *** search
- ''
- '' $Id: TimerArithmetic.bas,v 1.2 1994/03/16 15:09:16 alex Rel $
- ''
- '' Example of timer device arithmetic functions
- ''
- '' Derived from RKM example (c) Copyright 1992 Commodore-Amiga, Inc.
- ''
-
- DEFINT A-Z
-
- 'REM $INCLUDE Exec.bh
- 'REM $INCLUDE Timer.bh
-
- LIBRARY OPEN "exec.library", LIBRARY_MINIMUM&
-
- SUB main
- STATIC tr&, time1&, time2&, time3&
- STATIC result&
-
- ' Get some memory for our structures (needs to be MEMF_PUBLIC)
- time1& = AllocMem&(timeval_sizeof, MEMF_PUBLIC& OR MEMF_CLEAR&)
- time2& = AllocMem&(timeval_sizeof, MEMF_PUBLIC& OR MEMF_CLEAR&)
- time3& = AllocMem&(timeval_sizeof, MEMF_PUBLIC& OR MEMF_CLEAR&)
- tr& = AllocMem&(timerequest_sizeof, MEMF_PUBLIC& OR MEMF_CLEAR&)
-
- ' Make sure we got the memory
- IF time1& AND time2& AND time3& AND tr& THEN
- ' Set up values to test time arithmetic with. In a real application these
- ' values might be filled in via the GET_SYSTIME command of the timer device
- POKEL time1& + tv_secs, 3 : POKEL time1& + tv_micro, 0 ' 3.0 seconds
- POKEL time2& + tv_secs, 2 : POKEL time2& + tv_micro, 500000 ' 2.5 seconds
- POKEL time3& + tv_secs, 1 : POKEL time3& + tv_micro, 900000 ' 1.9 seconds
-
- PRINT "Time1 is"; PEEKL(time1& + tv_secs); "."; PEEKL(time1& + tv_micro)
- PRINT "Time2 is"; PEEKL(time2& + tv_secs); "."; PEEKL(time2& + tv_micro)
- PRINT "Time3 is"; PEEKL(time3& + tv_secs); "."; PEEKL(time3& + tv_micro)
-
- ' Open the MICROHZ timer device
- IF OpenDevice&(SADD("timer.device" + CHR$(0)), UNIT_MICROHZ&, tr&, 0) = 0 THEN
- ' Set up to use the special time arithmetic functions
- LIBRARY VARPTR "timer.device", PEEKL(tr& + tr_node + IORequestio_Device)
-
- ' Now that TimerBase is initialised, it is permissible to call
- ' the time-comparison or time-arithmetic routines. Result of
- ' this example is -1 which means the first parameter has greater
- ' time value than second parameter +1 means the second parameter
- ' is bigger; 0 means equal
-
- result& = CmpTime&(time1&, time2&)
- PRINT "Time1 and Time2 compare ="; result&
-
- ' Add time2 to time1, result in time1
- AddTime time1&, time2&
- PRINT "Time1 + Time2 ="; PEEKL(time1& + tv_secs); "."; PEEKL(time1& + tv_micro)
-
- ' Subtract time3 from time2, result in time2
- SubTime time2&, time3&
- PRINT "Time2 - Time3"; PEEKL(time2& + tv_secs); "."; PEEKL(time2& + tv_micro)
-
- LIBRARY VARPTR "timer.device", NULL&
- CloseDevice tr&
- END IF
- END IF
- IF time1& THEN FreeMem time1&, timeval_sizeof
- IF time2& THEN FreeMem time2&, timeval_sizeof
- IF time3& THEN FreeMem time3&, timeval_sizeof
- IF tr& THEN FreeMem tr&, timerequest_sizeof
- END SUB
-
- main
- END
-